home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Python 1.1 / Doc / libfcntl.tex / libfcntl.txt
LaTeX Document  |  1994-08-08  |  2.3 KB

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: LaTeX Document (document/latex).

You can browse this item here: libfcntl.txt

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file LaTeX document, ASCII text default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% gt2 Textdatei (UNIX) default
100% detectItEasy Format: plain text[LF] default (weak)



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 25 20 4d 61 6e 75 61 6c | 20 74 65 78 74 20 62 79 |% Manual| text by|
|00000010| 20 4a 61 61 70 20 56 65 | 72 6d 65 75 6c 65 6e 0a | Jaap Ve|rmeulen.|
|00000020| 5c 73 65 63 74 69 6f 6e | 7b 42 75 69 6c 74 2d 69 |\section|{Built-i|
|00000030| 6e 20 6d 6f 64 75 6c 65 | 20 5c 73 65 63 74 63 6f |n module| \sectco|
|00000040| 64 65 7b 66 63 6e 74 6c | 7d 7d 0a 5c 62 69 6d 6f |de{fcntl|}}.\bimo|
|00000050| 64 69 6e 64 65 78 7b 66 | 63 6e 74 6c 7d 0a 5c 69 |dindex{f|cntl}.\i|
|00000060| 6e 64 65 78 69 69 7b 55 | 4e 49 58 7d 7b 66 69 6c |ndexii{U|NIX}{fil|
|00000070| 65 20 63 6f 6e 74 72 6f | 6c 7d 0a 5c 69 6e 64 65 |e contro|l}.\inde|
|00000080| 78 69 69 7b 55 4e 49 58 | 7d 7b 49 4f 20 63 6f 6e |xii{UNIX|}{IO con|
|00000090| 74 72 6f 6c 7d 0a 54 68 | 69 73 20 6d 6f 64 75 6c |trol}.Th|is modul|
|000000a0| 65 20 70 65 72 66 6f 72 | 6d 73 20 66 69 6c 65 20 |e perfor|ms file |
|000000b0| 63 6f 6e 74 72 6f 6c 20 | 61 6e 64 20 49 4f 20 63 |control |and IO c|
|000000c0| 6f 6e 74 72 6f 6c 20 6f | 6e 20 66 69 6c 65 20 64 |ontrol o|n file d|
|000000d0| 65 73 63 72 69 70 74 6f | 72 73 2e 0a 49 74 20 69 |escripto|rs..It i|
|000000e0| 73 20 61 6e 20 69 6e 74 | 65 72 66 61 63 65 20 74 |s an int|erface t|
|000000f0| 6f 20 74 68 65 20 5c 64 | 66 6e 7b 66 63 6e 74 6c |o the \d|fn{fcntl|
|00000100| 28 29 7d 20 61 6e 64 20 | 5c 64 66 6e 7b 69 6f 63 |()} and |\dfn{ioc|
|00000110| 74 6c 28 29 7d 20 5c 55 | 4e 49 58 20 72 6f 75 74 |tl()} \U|NIX rout|
|00000120| 69 6e 65 73 2e 0a 46 69 | 6c 65 20 64 65 73 63 72 |ines..Fi|le descr|
|00000130| 69 70 74 6f 72 73 20 63 | 61 6e 20 62 65 20 6f 62 |iptors c|an be ob|
|00000140| 74 61 69 6e 65 64 20 77 | 69 74 68 20 74 68 65 20 |tained w|ith the |
|00000150| 5c 64 66 6e 7b 66 69 6c | 65 6e 6f 28 29 7d 20 6d |\dfn{fil|eno()} m|
|00000160| 65 74 68 6f 64 20 6f 66 | 20 61 0a 66 69 6c 65 20 |ethod of| a.file |
|00000170| 6f 72 20 73 6f 63 6b 65 | 74 20 6f 62 6a 65 63 74 |or socke|t object|
|00000180| 2e 0a 54 68 65 20 6d 6f | 64 75 6c 65 20 64 65 66 |..The mo|dule def|
|00000190| 69 6e 65 73 20 74 68 65 | 20 66 6f 6c 6c 6f 77 69 |ines the| followi|
|000001a0| 6e 67 20 66 75 6e 63 74 | 69 6f 6e 73 3a 0a 5c 72 |ng funct|ions:.\r|
|000001b0| 65 6e 65 77 63 6f 6d 6d | 61 6e 64 7b 5c 69 6e 64 |enewcomm|and{\ind|
|000001c0| 65 78 73 75 62 69 74 65 | 6d 7d 7b 28 69 6e 20 6d |exsubite|m}{(in m|
|000001d0| 6f 64 75 6c 65 20 73 74 | 72 75 63 74 29 7d 0a 5c |odule st|ruct)}.\|
|000001e0| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|000001f0| 66 63 6e 74 6c 7d 7b 66 | 64 5c 2c 20 6f 70 5c 6f |fcntl}{f|d\, op\o|
|00000200| 70 74 69 6f 6e 61 6c 7b | 5c 2c 20 61 72 67 7d 7d |ptional{|\, arg}}|
|00000210| 0a 20 20 50 65 72 66 6f | 72 6d 20 74 68 65 20 72 |. Perfo|rm the r|
|00000220| 65 71 75 65 73 74 65 64 | 20 6f 70 65 72 61 74 69 |equested| operati|
|00000230| 6f 6e 20 6f 6e 20 66 69 | 6c 65 20 64 65 73 63 72 |on on fi|le descr|
|00000240| 69 70 74 6f 72 20 5c 63 | 6f 64 65 7b 5c 76 61 72 |iptor \c|ode{\var|
|00000250| 7b 66 64 7d 7d 2e 0a 20 | 20 54 68 65 20 6f 70 65 |{fd}}.. | The ope|
|00000260| 72 61 74 69 6f 6e 20 69 | 73 20 64 65 66 69 6e 65 |ration i|s define|
|00000270| 64 20 62 79 20 5c 63 6f | 64 65 7b 5c 76 61 72 7b |d by \co|de{\var{|
|00000280| 6f 70 7d 7d 20 61 6e 64 | 20 69 73 20 6f 70 65 72 |op}} and| is oper|
|00000290| 61 74 69 6e 67 20 73 79 | 73 74 65 6d 0a 20 20 64 |ating sy|stem. d|
|000002a0| 65 70 65 6e 64 65 6e 74 | 2e 20 20 54 79 70 69 63 |ependent|. Typic|
|000002b0| 61 6c 6c 79 20 74 68 65 | 73 65 20 63 6f 64 65 73 |ally the|se codes|
|000002c0| 20 63 61 6e 20 62 65 20 | 72 65 74 72 69 65 76 65 | can be |retrieve|
|000002d0| 64 20 66 72 6f 6d 20 74 | 68 65 20 6c 69 62 72 61 |d from t|he libra|
|000002e0| 72 79 0a 20 20 6d 6f 64 | 75 6c 65 20 5c 63 6f 64 |ry. mod|ule \cod|
|000002f0| 65 7b 46 43 4e 54 4c 7d | 2e 20 54 68 65 20 61 72 |e{FCNTL}|. The ar|
|00000300| 67 75 6d 65 6e 74 20 5c | 63 6f 64 65 7b 5c 76 61 |gument \|code{\va|
|00000310| 72 7b 61 72 67 7d 7d 20 | 69 73 20 6f 70 74 69 6f |r{arg}} |is optio|
|00000320| 6e 61 6c 2c 20 61 6e 64 | 0a 20 20 64 65 66 61 75 |nal, and|. defau|
|00000330| 6c 74 73 20 74 6f 20 74 | 68 65 20 69 6e 74 65 67 |lts to t|he integ|
|00000340| 65 72 20 76 61 6c 75 65 | 20 5c 63 6f 64 65 7b 30 |er value| \code{0|
|00000350| 7d 2e 20 20 57 68 65 6e | 0a 20 20 69 74 20 69 73 |}. When|. it is|
|00000360| 20 70 72 65 73 65 6e 74 | 2c 20 69 74 20 63 61 6e | present|, it can|
|00000370| 20 65 69 74 68 65 72 20 | 62 65 20 61 6e 20 69 6e | either |be an in|
|00000380| 74 65 67 65 72 20 76 61 | 6c 75 65 2c 20 6f 72 20 |teger va|lue, or |
|00000390| 61 20 73 74 72 69 6e 67 | 2e 20 20 57 69 74 68 0a |a string|. With.|
|000003a0| 20 20 74 68 65 20 61 72 | 67 75 6d 65 6e 74 20 6d | the ar|gument m|
|000003b0| 69 73 73 69 6e 67 20 6f | 72 20 61 6e 20 69 6e 74 |issing o|r an int|
|000003c0| 65 67 65 72 20 76 61 6c | 75 65 2c 20 74 68 65 20 |eger val|ue, the |
|000003d0| 72 65 74 75 72 6e 20 76 | 61 6c 75 65 20 6f 66 20 |return v|alue of |
|000003e0| 74 68 69 73 0a 20 20 66 | 75 6e 63 74 69 6f 6e 20 |this. f|unction |
|000003f0| 69 73 20 74 68 65 20 69 | 6e 74 65 67 65 72 20 72 |is the i|nteger r|
|00000400| 65 74 75 72 6e 20 76 61 | 6c 75 65 20 6f 66 20 74 |eturn va|lue of t|
|00000410| 68 65 20 72 65 61 6c 20 | 5c 63 6f 64 65 7b 66 63 |he real |\code{fc|
|00000420| 6e 74 6c 28 29 7d 0a 20 | 20 63 61 6c 6c 2e 20 20 |ntl()}. | call. |
|00000430| 57 68 65 6e 20 74 68 65 | 20 61 72 67 75 6d 65 6e |When the| argumen|
|00000440| 74 20 69 73 20 61 20 73 | 74 72 69 6e 67 20 69 74 |t is a s|tring it|
|00000450| 20 72 65 70 72 65 73 65 | 6e 74 73 20 61 20 62 69 | represe|nts a bi|
|00000460| 6e 61 72 79 0a 20 20 73 | 74 72 75 63 74 75 72 65 |nary. s|tructure|
|00000470| 2c 20 65 2e 67 2e 20 20 | 63 72 65 61 74 65 64 20 |, e.g. |created |
|00000480| 62 79 20 5c 63 6f 64 65 | 7b 73 74 72 75 63 74 2e |by \code|{struct.|
|00000490| 70 61 63 6b 28 29 7d 2e | 20 54 68 65 20 62 69 6e |pack()}.| The bin|
|000004a0| 61 72 79 20 64 61 74 61 | 20 69 73 0a 20 20 63 6f |ary data| is. co|
|000004b0| 70 69 65 64 20 74 6f 20 | 61 20 62 75 66 66 65 72 |pied to |a buffer|
|000004c0| 20 77 68 6f 73 65 20 61 | 64 64 72 65 73 73 20 69 | whose a|ddress i|
|000004d0| 73 20 70 61 73 73 65 64 | 20 74 6f 20 74 68 65 20 |s passed| to the |
|000004e0| 72 65 61 6c 20 5c 63 6f | 64 65 7b 66 63 6e 74 6c |real \co|de{fcntl|
|000004f0| 28 29 7d 0a 20 20 63 61 | 6c 6c 2e 20 20 54 68 65 |()}. ca|ll. The|
|00000500| 20 72 65 74 75 72 6e 20 | 76 61 6c 75 65 20 61 66 | return |value af|
|00000510| 74 65 72 20 61 20 73 75 | 63 63 65 73 73 66 75 6c |ter a su|ccessful|
|00000520| 20 63 61 6c 6c 20 69 73 | 20 74 68 65 20 63 6f 6e | call is| the con|
|00000530| 74 65 6e 74 73 20 6f 66 | 0a 20 20 74 68 65 20 62 |tents of|. the b|
|00000540| 75 66 66 65 72 2c 20 63 | 6f 6e 76 65 72 74 65 64 |uffer, c|onverted|
|00000550| 20 74 6f 20 61 20 73 74 | 72 69 6e 67 20 6f 62 6a | to a st|ring obj|
|00000560| 65 63 74 2e 20 20 49 6e | 20 74 68 65 20 63 61 73 |ect. In| the cas|
|00000570| 65 20 74 68 65 0a 20 20 | 5c 63 6f 64 65 7b 66 63 |e the. |\code{fc|
|00000580| 6e 74 6c 28 29 7d 20 66 | 61 69 6c 73 2c 20 61 6e |ntl()} f|ails, an|
|00000590| 20 5c 63 6f 64 65 7b 49 | 4f 45 72 72 6f 72 7d 20 | \code{I|OError} |
|000005a0| 77 69 6c 6c 20 62 65 20 | 72 61 69 73 65 64 2e 0a |will be |raised..|
|000005b0| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0a 5c |\end{fun|cdesc}.\|
|000005c0| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|000005d0| 69 6f 63 74 6c 7d 7b 66 | 64 5c 2c 20 6f 70 5c 2c |ioctl}{f|d\, op\,|
|000005e0| 20 61 72 67 7d 0a 20 20 | 54 68 69 73 20 66 75 6e | arg}. |This fun|
|000005f0| 63 74 69 6f 6e 20 69 73 | 20 69 64 65 6e 74 69 63 |ction is| identic|
|00000600| 61 6c 20 74 6f 20 74 68 | 65 20 5c 63 6f 64 65 7b |al to th|e \code{|
|00000610| 66 63 6e 74 6c 28 29 7d | 20 66 75 6e 63 74 69 6f |fcntl()}| functio|
|00000620| 6e 2c 20 65 78 63 65 70 | 74 0a 20 20 74 68 61 74 |n, excep|t. that|
|00000630| 20 74 68 65 20 6f 70 65 | 72 61 74 69 6f 6e 73 20 | the ope|rations |
|00000640| 61 72 65 20 74 79 70 69 | 63 61 6c 6c 79 20 64 65 |are typi|cally de|
|00000650| 66 69 6e 65 64 20 69 6e | 20 74 68 65 20 6c 69 62 |fined in| the lib|
|00000660| 72 61 72 79 20 6d 6f 64 | 75 6c 65 0a 20 20 5c 63 |rary mod|ule. \c|
|00000670| 6f 64 65 7b 49 4f 43 54 | 4c 7d 2e 0a 5c 65 6e 64 |ode{IOCT|L}..\end|
|00000680| 7b 66 75 6e 63 64 65 73 | 63 7d 0a 49 66 20 74 68 |{funcdes|c}.If th|
|00000690| 65 20 6c 69 62 72 61 72 | 79 20 6d 6f 64 75 6c 65 |e librar|y module|
|000006a0| 73 20 5c 63 6f 64 65 7b | 46 43 4e 54 4c 7d 20 6f |s \code{|FCNTL} o|
|000006b0| 72 20 5c 63 6f 64 65 7b | 49 4f 43 54 4c 7d 20 61 |r \code{|IOCTL} a|
|000006c0| 72 65 20 6d 69 73 73 69 | 6e 67 2c 20 79 6f 75 0a |re missi|ng, you.|
|000006d0| 63 61 6e 20 66 69 6e 64 | 20 74 68 65 20 6f 70 63 |can find| the opc|
|000006e0| 6f 64 65 73 20 69 6e 20 | 74 68 65 20 43 20 69 6e |odes in |the C in|
|000006f0| 63 6c 75 64 65 20 66 69 | 6c 65 73 20 5c 63 6f 64 |clude fi|les \cod|
|00000700| 65 7b 73 79 73 2f 66 63 | 6e 74 6c 7d 20 61 6e 64 |e{sys/fc|ntl} and|
|00000710| 0a 5c 63 6f 64 65 7b 73 | 79 73 2f 69 6f 63 74 6c |.\code{s|ys/ioctl|
|00000720| 7d 2e 20 59 6f 75 20 63 | 61 6e 20 63 72 65 61 74 |}. You c|an creat|
|00000730| 65 20 74 68 65 20 6d 6f | 64 75 6c 65 73 20 79 6f |e the mo|dules yo|
|00000740| 75 72 73 65 6c 66 20 77 | 69 74 68 20 74 68 65 20 |urself w|ith the |
|00000750| 68 32 70 79 0a 73 63 72 | 69 70 74 2c 20 66 6f 75 |h2py.scr|ipt, fou|
|00000760| 6e 64 20 69 6e 20 74 68 | 65 20 5c 63 6f 64 65 7b |nd in th|e \code{|
|00000770| 44 65 6d 6f 2f 73 63 72 | 69 70 74 73 7d 20 64 69 |Demo/scr|ipts} di|
|00000780| 72 65 63 74 6f 72 79 2e | 0a 45 78 61 6d 70 6c 65 |rectory.|.Example|
|00000790| 73 20 28 61 6c 6c 20 6f | 6e 20 61 20 53 56 52 34 |s (all o|n a SVR4|
|000007a0| 20 63 6f 6d 70 6c 69 61 | 6e 74 20 73 79 73 74 65 | complia|nt syste|
|000007b0| 6d 29 3a 0a 5c 62 63 6f | 64 65 5c 62 65 67 69 6e |m):.\bco|de\begin|
|000007c0| 7b 76 65 72 62 61 74 69 | 6d 7d 0a 69 6d 70 6f 72 |{verbati|m}.impor|
|000007d0| 74 20 73 74 72 75 63 74 | 2c 20 46 43 4e 54 4c 0a |t struct|, FCNTL.|
|000007e0| 66 69 6c 65 20 3d 20 6f | 70 65 6e 28 2e 2e 2e 29 |file = o|pen(...)|
|000007f0| 0a 72 76 20 3d 20 66 63 | 6e 74 6c 28 66 69 6c 65 |.rv = fc|ntl(file|
|00000800| 2e 66 69 6c 65 6e 6f 28 | 29 2c 20 46 43 4e 54 4c |.fileno(|), FCNTL|
|00000810| 2e 4f 5f 4e 44 45 4c 41 | 59 2c 20 31 29 0a 6c 6f |.O_NDELA|Y, 1).lo|
|00000820| 63 6b 64 61 74 61 20 3d | 20 73 74 72 75 63 74 2e |ckdata =| struct.|
|00000830| 70 61 63 6b 28 27 68 68 | 6c 6c 68 68 27 2c 20 46 |pack('hh|llhh', F|
|00000840| 43 4e 54 4c 2e 46 5f 57 | 52 4c 43 4b 2c 20 30 2c |CNTL.F_W|RLCK, 0,|
|00000850| 20 30 2c 20 30 2c 20 30 | 2c 20 30 29 0a 72 76 20 | 0, 0, 0|, 0).rv |
|00000860| 3d 20 66 63 6e 74 6c 28 | 66 69 6c 65 2e 66 69 6c |= fcntl(|file.fil|
|00000870| 65 6e 6f 28 29 2c 20 46 | 43 4e 54 4c 2e 46 5f 53 |eno(), F|CNTL.F_S|
|00000880| 45 54 4c 4b 57 2c 20 6c | 6f 63 6b 64 61 74 61 29 |ETLKW, l|ockdata)|
|00000890| 0a 5c 65 6e 64 7b 76 65 | 72 62 61 74 69 6d 7d 5c |.\end{ve|rbatim}\|
|000008a0| 65 63 6f 64 65 0a 4e 6f | 74 65 20 74 68 61 74 20 |ecode.No|te that |
|000008b0| 69 6e 20 74 68 65 20 66 | 69 72 73 74 20 65 78 61 |in the f|irst exa|
|000008c0| 6d 70 6c 65 20 74 68 65 | 20 72 65 74 75 72 6e 20 |mple the| return |
|000008d0| 76 61 6c 75 65 20 76 61 | 72 69 61 62 6c 65 20 5c |value va|riable \|
|000008e0| 63 6f 64 65 7b 72 76 7d | 20 77 69 6c 6c 0a 68 6f |code{rv}| will.ho|
|000008f0| 6c 64 20 61 6e 20 69 6e | 74 65 67 65 72 20 76 61 |ld an in|teger va|
|00000900| 6c 75 65 3b 20 69 6e 20 | 74 68 65 20 73 65 63 6f |lue; in |the seco|
|00000910| 6e 64 20 65 78 61 6d 70 | 6c 65 20 69 74 20 77 69 |nd examp|le it wi|
|00000920| 6c 6c 20 68 6f 6c 64 20 | 61 20 73 74 72 69 6e 67 |ll hold |a string|
|00000930| 0a 76 61 6c 75 65 2e 0a | |.value..| |
+--------+-------------------------+-------------------------+--------+--------+